package com.hddf.project.util;

public class GetRealPath {
	// ------------------------------------------------------------------------------------------------------------------------------------
	// 绝对路径
	// ------------------------------------------------------------------------------------------------------------------------------------
	/**
	 * 获取项目的绝对路径.
	 * 
	 * @return
	 */
	public String getRealPath() {
		String prefix = "";
		try {
			prefix = HttpUtil.getServletContext().getRealPath("/");
			if (StringUtil.isEmpty(prefix)) {
				prefix = getClass().getResource("/").getPath();
				int index = prefix.indexOf("WEB-INF");
				if (index == -1) {
					index = prefix.indexOf("bin");
				}
				prefix = prefix.substring(0, index);
				if (prefix.startsWith("zip")) {
					prefix = prefix.substring(4);
				} else if (prefix.startsWith("file")) {
					prefix = prefix.substring(6);
				} else if (prefix.startsWith("jar")) {
					prefix = prefix.substring(10);
				}
				prefix = prefix.replace("%20", " ");
			}
		} catch (Exception e) {
			prefix = getClass().getResource("/").getPath();
			int index = prefix.indexOf("WEB-INF");
			if (index == -1) {
				index = prefix.indexOf("bin");
			}
			prefix = prefix.substring(0, index);
			if (prefix.startsWith("zip")) {
				prefix = prefix.substring(4);
			} else if (prefix.startsWith("file")) {
				prefix = prefix.substring(6);
			} else if (prefix.startsWith("jar")) {
				prefix = prefix.substring(10);
			}
			prefix = prefix.replace("%20", " ");
		}
		return prefix;
	}

}
